package com.zhu.storesmanager.utils;

import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.zhu.storesmanager.R;
import com.zhu.storesmanager.views.ChoiceView;

/**
 * 界面静态
 */
public class ViewsUtil {

    /**
     * 设置选择框界面
     * @return ChoiceView 选择框界面
     * @param parentView 父View
     * @param textId 文本id
     */
    public static ChoiceView setChoiceView(View parentView, int textId){
        ChoiceView choiceView = (ChoiceView)parentView.findViewById(R.id.sv_choiceview);
        ((TextView)parentView.findViewById(R.id.sv_choiceview_lable)).setText(textId);
        return choiceView;
    }

    /**
     * 设置输入文本界面
     * @return editText 输入框
     * @param parentView 父View
     * @param textId 文本id
     */
    public static EditText setEditTextView(View parentView, int textId){
        EditText editText = (EditText)parentView.findViewById(R.id.sv_edittext);
        ((TextView)parentView.findViewById(R.id.sv_edittext_label)).setText(textId);
        return editText;
    }

    /**
     * 设置显示文本内容
     * @param view 父View
     * @param textViewId 文本viewID
     * @param text 文本内容
     */
    public static void setTextViewData(View view, int textViewId, String text){
        ((TextView)view.findViewById(textViewId)).setText(text);
    }

    /**
     * 禁用RadioGroup
     * @param radioGroup
     */
    public static void setRadioGroupdisable(RadioGroup radioGroup){
    	int selecID = radioGroup.getCheckedRadioButtonId();
    	View selectView = null;
    	if(selecID != -1){
    		selectView = radioGroup.findViewById(selecID);
    	}
    	for(int i = 0; i < radioGroup.getChildCount(); i++){ //遍历所有
    		View view = radioGroup.getChildAt(i);
    		if(selectView != null && selectView == view){ //忽略选中
    			
    		}else{
    			view.setEnabled(false);
    		}
    	}
    }

    /**
	 * 检测选择View是否 有数据
	 * @param isShow 是否显示
	 * @param choiceView 界面
	 * @return true 有数据 否则false
	 */
	public static boolean checkChoiceViewData(boolean isShow, ChoiceView choiceView){
		if(!isShow){
			return true;
		}
		return !Actions.isNull(choiceView.getSaveData());			
	}
}
